package cn.jit.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import cn.jit.dao.UserDao;
import cn.jit.po.User;
import cn.jit.service.UserService;
import sun.security.util.Length;

@Service("userService")
public class UserServiceImpl implements UserService{
	
	@Resource
    private UserDao userDao;
	
	@Override
	public int addUser(User user) {
		return userDao.addUser(user);
	}

	@Override
	public User getUserForlogin(User user) {
		User returnUser = userDao.getUserForlogin(user);
		return returnUser;
	}

	@Override
	public ArrayList<User> getUsers(User user) {
		ArrayList<User> users = userDao.getUsers(user);
		return users;
	}

	@Override
	public int deleteUserLogically(User user) {
		int result = userDao.deleteUserLogically(user);
		
		return result;
	}

	@Override
	public boolean updateUser(User user) {
		Integer result = userDao.updateUser(user);
		if (result > 0) {
			return true;
		}
		return false;
	}

	@Override
	public User getUser(Integer userId) {
		User user = new User();
		user.setUserId(userId);
		return userDao.getUser(user);
	}
	
	@Override
	public boolean getUser(String email) {
		User user = new User();
		user.setEmail(email);
		User result = userDao.getUser(user);
		if (result != null) {
			return true;
		}
		return false;
	}
	
	@Override
	public boolean updatePwd(String email, String pwd) {
		User user = new User();
		user.setPassword(pwd);
		user.setEmail(email);
		int result = userDao.updatePwd(user);
		if (result > 0) {
			return true;
		}
		return false;
	}

	@Override
	public int count(User user) {
		return userDao.count(user);
	}

	@Override
	public ArrayList<User> getUsers(Integer start,Integer rows) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", start);
		map.put("rows", rows);
		return userDao.getUserPage(map);
	}
	
	
	
}
